// pages/like/like.js
const app = getApp()
import { route } from '../../utils/util'
let that;
Page({
  data: {
    current: 0,
    minutes: 0,
    seconds: 0,
    readytext: true,
    timer: null,
    tabheight:app.globalData.phone_height
  },
  onLoad: function (options) {
    
  },
  onShow: function () {
    this.setData({
      minutes: 0,
      seconds: 0
    })
  },
  // 模式切换
  swiper_change(e) {
    let current = e.detail.current
    this.setData({ current })
  },
  // 点我开始
  btnReady() {
    that = this
    that.getTimer()
    that.setData({
      readytext: !that.data.readytext
    })
  },
  // 结束
  btnEnd() {
    that = this
    let minutes = that.data.minutes;
    let seconds = that.data.seconds;
    clearInterval(that.timer)
    that.setData({
      readytext: !that.data.readytext
    })
    let sendData = { minutes, seconds };
    route('/pages/record/record', sendData)

  },
  // 计时模式
  getTimer() {
    that = this
    that.timer = that.data.timer;
    let minutes = 0;
    let seconds = 0;
    clearInterval(that.timer)
    that.timer = setInterval(function () {
      seconds = seconds + 1
      if (seconds > 59) {
        seconds = 0
        if (minutes > 59) {
          console.log('你也太能拉了吧！');
          return clearInterval(that.timer)
        }
        minutes = minutes + 1
        that.setData({
          seconds,
          minutes
        })
      } else {
        that.setData({
          seconds
        })
      }
    }, 1000)

  },

})